import { ref, reactive, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  function increment(arg) {
    count.value = count.value + arg;
  }
  return { count, doubleCount, increment }
})

export const useTableDataStore = defineStore('tableDataer', () => {
  const allData = reactive([])
  function pushData2TableData(param, isPoint) {
    param.forEach(item => {
      if (item.hasOwnProperty('isData')) {
        item.treeData = [];
      }
      allData.push(item)
    })
  }

  function pushData2TableData2(param) {
    var pid = param.pid;
    var data = param.data;
    allData.forEach(point => {
      if (point.id && pid == point.id) {
        data.forEach(item => {
          point.treeData.push(item);
        })
      }
    })
  }

  function pushData2TableData3(param) {
    var pointArr = param.events;
    pointArr.forEach(point=>{
      pushData2TableData2(point);
    })
  }
  return { allData, pushData2TableData, pushData2TableData2, pushData2TableData3 }
})